package com.stu.day11.clone;

import java.util.Arrays;

/**
 * 实现Cloneable接口重写clone方法实现浅克隆
 * @Override
 * protected Object clone() throws CloneNotSupportedException {
 *     return super.clone(); // 调用Object的clone()方法，进行浅克隆
 * }
 * @author mm
 * @date 2025/1/16 11:29:40
 */
public class User implements Cloneable{
    private int id;
    private String name;
    private int age;
    private Book[] book;

    public User(int id, String name, int age, Book[] book) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.book = book;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Book[] getBook() {
        return book;
    }

    public void setBook(Book[] book) {
        this.book = book;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();      //浅拷贝
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("User{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", book=").append(Arrays.toString(book));
        sb.append('}');
        return sb.toString();
    }
}
